﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;

namespace BGShell.Drawing
{
    [Serializable]
    [SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
    public enum TypeModelIcon
    {
        None = 0,
        Class = 1,
        Constant = 2,
        Delegate = 3,
        Enum = 4,
        EnumValue = 5,
        Event = 6,
        // Unknown = 7,
        Field = 8,
        Interface = 9,
        // Unknown = 10,
        // Unknown = 11,
        Method = 12,
        MethodGroup = 13,
        // Unknown = 14,
        Property = 15,
        Structure = 16,
        GenericArgument = 17,
        // Unknown = 18,
        // Unknown = 19,
        // Unknown = 20,
        // Unknown = 21,
        // Unknown = 22,
        OverlayPrivate = 23,
        OverlayProtected = 24,
        OverlayInternal = 25,
        // OverlayUnknown = 26,
        OverlayStatic = 27,
        OverlayAlias = 28,
        OverlayAssembly = 29,
        // OverlayScript = 30,
        ScriptProperty = 31,
        Error = 32,
        // Unknown = 31,
        // Unknown = 32,
        // Unknown = 33,
    }

    [Serializable]
    public enum TypeModelIconOverlay
    {
        None = 0,
        Private = 23,
        Protected = 24,
        Internal = 25,
        // Unknown = 26,
        Static = 27,
        Alias = 28,
        Assembly = 29,
    }

    public static class TypeModelIconRenderer
    {
        public static void RenderIcon(Graphics graphics, Rectangle rect, TypeModelIcon icon, TypeModelIconOverlay overlay)
        {
            var bmp = Resources.TypeModelIcons;
            var destRect = new Rectangle(rect.X, rect.Y, bmp.Height, bmp.Height);

            var iconIndex = (int)(icon);
            var overlayIndex = (int)(overlay);

            if (icon != TypeModelIcon.None)
            {
                graphics.DrawImage(bmp, destRect, GetSrcRect(bmp, iconIndex), GraphicsUnit.Pixel);
            }

            if (overlay != TypeModelIconOverlay.None)
            {
                graphics.DrawImage(bmp, destRect, GetSrcRect(bmp, overlayIndex), GraphicsUnit.Pixel);
            }
        }

        private static Rectangle GetSrcRect(Bitmap bmp, int index)
        {
            return new Rectangle((index - 1) * bmp.Height, 0, bmp.Height, bmp.Height);
        }
    }
}
